﻿using DemountCIM.Framework.DataBase;
using DemountCIM.Framework.DataBase.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfUIDLL.MessageBox;

namespace DemountCIM.Windows
{
    /// <summary>
    /// PwdModifyWindow.xaml 的交互逻辑
    /// </summary>
    public partial class PwdModifyWindow : Window
    {
        private TbUser _curUser;

        public PwdModifyWindow()
        {
            InitializeComponent();

            this.Topmost = true;
        }

        public void SetUserInfo(TbUser user)
        {
            this._curUser = user;

            UserName.Text = user.Name;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void AduFlatButton_Click(object sender, RoutedEventArgs e)
        {
            {
                if (this.NewPassWord.Password == this.ConfirmPassWord.Password)
                {
                    try
                    {
                        var user = new TbUser
                        {
                            Id = this._curUser.Id,
                            Name = this.UserName.Text,
                            Pwd = this.NewPassWord.Password,
                            Level = this._curUser.Level,
                        };
                        if (!DataBaseContainer.GetInstance().GetUserRepository().ModifyUserInfo(user))
                        {
                            ShowMsgBox.ShowDialog("尝试修改用户信息失败", MessageType.MsgAlarm);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        ShowMsgBox.ShowDialog("尝试修改用户信息失败", MessageType.MsgAlarm);
                    }
                }
                else
                {
                    ShowMsgBox.ShowDialog("新密码和二次确认密码不相同，无法更改！", MessageType.MsgAlarm);
                    return;
                }
            }

            this.Close();
        }

        private void AduFlatButton_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
